package com.example.demo.Controller;

import com.example.demo.Entity.Directoryitem;
import com.example.demo.Entity.Note;
import com.example.demo.Service.DirectoryitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/directoryitem")
public class DirectoryitemController {

    @Autowired
  private DirectoryitemService directoryitemService;

    @GetMapping("/getDirectoryitemByUserId")
    public List<Directoryitem> getDirectoryitemByUserId(@RequestParam Integer userId) {
        return  directoryitemService.findDirectoryitemByUserId(userId);
    }
    @DeleteMapping("/Delete")
    public void DeleteDirectoryitem(@RequestBody Directoryitem directoryitem) {
        directoryitemService.deleteDirectoryitem(directoryitem);
    }
    @PostMapping("/Insert")
    public void InsertDirectoryitem(@RequestBody Directoryitem directoryitem) {
        directoryitemService.insertDirectoryitem(directoryitem);
    }
    @PostMapping("/Update")
    public void UpdateDirectoryitem(@RequestBody Directoryitem directoryitem) {
        directoryitemService.updateDirectoryitem(directoryitem);
    }

    @GetMapping("/GetNote")
    public List<Note> getAllNote(@RequestParam int directoryId){
        return directoryitemService.findNoteByDirectoryId(directoryId);
    }
    @DeleteMapping("/deleteByDirectoryId")
    public void delete(@RequestParam Integer directoryId) {
        directoryitemService.deleteDirectoryitemById(directoryId);
    }

    @GetMapping("/selectByDirectoryId")
    public Directoryitem selectByDirectoryId(@RequestParam Integer directoryId){
        return    directoryitemService.selectByDirectoryId(directoryId);
    }
    @GetMapping("/selectByDirectoryName")
        public Directoryitem selectByDirectoryName(@RequestParam String directoryName){
        return    directoryitemService.selectByDirectoryName(directoryName);
    }


}
